package 算法.leetcode.bytedance;

import 算法.leetcode.offer.base.ListNode;

/**
 * @author lchenglong
 * @date 2022/5/15
 */
public class OfferLinked_I {
    public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
        if (list1==null)return list2;
        if (list2==null)return list1;
        ListNode vHead = new ListNode(-1);
        ListNode cursor = vHead;
        while (list1!=null&&list2!=null){
            if (list1.val<=list2.val){
                cursor.next = list1;
                list1 = list1.next;
            } else {
                cursor.next = list2;
                list2 = list2.next;
            }
            cursor = cursor.next;
        }
        cursor.next = list1==null?list2:list1;
        return vHead.next;
    }
}
